/*
 * Copyright Notice ====================================================
 * This file contains proprietary information of JeeStrap Co.
 * Copying or reproduction without prior written approval is prohibited.
 * Copyright (c) 2014 All rights reserved. =============================
 */

package com.jeestrap.common.smartcoder.gui.setting.jtable;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.jeestrap.common.smartcoder.domain.OrmTableField;

public class OrmTableModel extends AbstractTableModel {
	/**
	 * serialVersionUID long
	 */
	private static final long serialVersionUID = 3537168103501108348L;

	private OrmTableColumn[] columns = {new OrmTableColumn("choosed", "有效"), 
	                                    new OrmTableColumn("fieldName", "字段"),
										new OrmTableColumn("fieldLabel", "备注"),
										new OrmTableColumn("fieldType", "类型"),
										new OrmTableColumn("primaryKey", "主键"),
										new OrmTableColumn("allowNull", "为空"),
										new OrmTableColumn("maxLength", "长度"),
										new OrmTableColumn("javaFieldName", "Java名"),
										new OrmTableColumn("javaMapClass", "Java类型"),
										new OrmTableColumn("jspQueryField", "查询字段"),
										new OrmTableColumn("jspQueryListField", "列表字段"),
										new OrmTableColumn("jspEditField", "编辑字段"),
										new OrmTableColumn("jspEditDataType", "验证类型"),
										new OrmTableColumn("jspFieldEditType", "控件类型"),
										new OrmTableColumn("jspComboxDataId", "SOID")};

	private List tableRowList = new ArrayList();

	public int getRowCount() {
		return this.tableRowList.size();
	}

	public int getColumnCount() {
		return this.columns.length;
	}

	public String getColumnId(int paramInt) {
		return this.columns[paramInt].getColId();
	}

	public String getColumnName(int paramInt) {
		return this.columns[paramInt].getcolDesc();
	}

	public Object getRow(int paramInt) {
		return this.tableRowList.get(paramInt);
	}

	public Object[] toArray() {
		return this.tableRowList.toArray();
	}

	public Object[] toArray(Object[] paramArrayOfObject) {
		return this.tableRowList.toArray(paramArrayOfObject);
	}

	public void removeAll() {
		int i = this.tableRowList.size();
		for (int j = 0; j < i; j++)
			removeRow(0);
	}

	public void addRow(OrmTableField paramOrmTableField) {
		this.tableRowList.add(paramOrmTableField);
		int i = this.tableRowList.size();
		fireTableRowsInserted(i - 1, i - 1);
	}

	public void addRow(int paramInt, OrmTableField paramOrmTableField) {
		this.tableRowList.add(paramInt, paramOrmTableField);
		fireTableRowsInserted(paramInt, paramInt);
	}

	public void setRow(int paramInt, OrmTableField paramOrmTableField) {
		this.tableRowList.set(paramInt, paramOrmTableField);
		fireTableRowsUpdated(paramInt, paramInt);
	}

	public void removeRow(int paramInt) {
		this.tableRowList.remove(paramInt);
		fireTableRowsDeleted(paramInt, paramInt);
	}

	public int removeRow(OrmTableField paramOrmTableField) {
		int i = this.tableRowList.indexOf(paramOrmTableField);
		if (i != -1) {
			this.tableRowList.remove(i);
			fireTableRowsDeleted(i, i);
			return i;
		}
		return -1;
	}

	public Object getValueAt(int paramInt1, int paramInt2) {
		Object localObject = getRow(paramInt1);
		if (localObject != null) {
			OrmTableField localOrmTableField = (OrmTableField)localObject;
			String str = getColumnId(paramInt2);
			return localOrmTableField.getPropertyValue(str);
		}
		return null;
	}

	public void setValueAt(Object paramObject, int paramInt1, int paramInt2) {
		if (this.columns != null) {
			Object localObject = getRow(paramInt1);
			if (localObject != null) {
				OrmTableField localOrmTableField = (OrmTableField)localObject;
				String str = getColumnId(paramInt2);
				localOrmTableField.setPropertyValue(str, paramObject);
				fireTableRowsDeleted(paramInt1, paramInt1);
			}
		}
	}

	public boolean isCellEditable(int paramInt1, int paramInt2) {
		boolean bool = false;
		switch (paramInt2) {
			case 0:
				bool = true;
				break;
			case 1:
				bool = false;
				break;
			case 2:
				bool = true;
				break;
			case 3:
				bool = false;
				break;
			case 4:
				bool = true;
				break;
			case 5:
				bool = true;
				break;
			case 6:
				bool = true;
				break;
			case 7:
				bool = true;
				break;
			case 8:
				bool = true;
				break;
			case 9:
				bool = true;
				break;
			case 10:
				bool = true;
				break;
			case 11:
				bool = true;
				break;
			case 12:
				bool = true;
				break;
			case 13:
				bool = true;
				break;
			case 14:
				bool = true;
				break;
			default:
				bool = false;
		}
		return bool;
	}

	public Class getColumnClass(int paramInt) {
		Class localClass = Object.class;
		switch (paramInt) {
			case 0:
				localClass = Boolean.class;
				break;
			case 1:
				localClass = String.class;
				break;
			case 2:
				localClass = String.class;
				break;
			case 3:
				localClass = String.class;
				break;
			case 4:
				localClass = Boolean.class;
				break;
			case 5:
				localClass = Boolean.class;
				break;
			case 6:
				localClass = Integer.class;
				break;
			case 7:
				localClass = String.class;
				break;
			case 8:
				localClass = String.class;
				break;
			case 9:
				localClass = Boolean.class;
				break;
			case 10:
				localClass = Boolean.class;
				break;
			case 11:
				localClass = Boolean.class;
				break;
			case 12:
				localClass = String.class;
				break;
			case 13:
				localClass = String.class;
				break;
			case 14:
				localClass = String.class;
				break;
			default:
				localClass = Object.class;
		}
		return localClass;
	}
}
